using System;
using System.Collections.Generic;
using System.Text;
using Vj.MathLibrary;
using System.Drawing;
using Vj.ShapeLibrary;
using ShapeLibrary;
using Vj.ShapeLibrary.Planar;

namespace Vj.ParticlesLibrary
{
    public class Particle : IShape
    {
        #region Properties

        protected int lifeSpan;

        public int LifeSpan
        {
            get { return lifeSpan; }
            set { lifeSpan = value; }
        }

        private int age;

        public int Age
        {
            get { return age; }
            set { age = value; }
        }

        protected bool kill = false;

        public bool Kill
        {
            get { return kill; }
        }

        protected Vector position;

        public Vector Position
        {
            get { return position; }
            set { position = value; }
        }

        protected Vector velocity;

        public Vector Velocity
        {
            get { return velocity; }
            set { velocity = value; }
        }

        protected Color color;

        public Color MyColor
        {
            get { return color; }
            set { color = value; }
        }

        #endregion

        public Particle(Vector position, Vector velocity, Color color, int lifeSpan)
        {
            this.position = position;
            this.velocity = velocity;
            this.color = color;

            this.lifeSpan = lifeSpan;
            this.age = 0;
        }

        Vector up = new Vector(0.0, 0.1, 0.0);

        public void Draw()
        {
            float intensity;

            if(this.lifeSpan == 0)
                intensity = 0.0f;
            else
                intensity = 1.0f - (float)this.age / (float)this.lifeSpan;

            //Color particleColor =
            //    Color.FromArgb((int)((float)this.color.R * intensity),
            //                   (int)((float)this.color.G * intensity),
            //                   (int)((float)this.color.B * intensity));


            //Ray.Draw(position, position+intensity*up, particleColor);

            //Ray.Draw(position, position + intensity * up, color);
            Line.Draw(position, position + up, color);


            if (age >= lifeSpan)
            {
                kill = true;
                return;
            }

            this.velocity += ParticleEnvironment.Instance.Gravity + ParticleEnvironment.Instance.Wind;
            this.position += this.velocity;


            age++;
        }
    }
}
